﻿
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using Components;
using Model;


namespace MsDAL
{
   public partial  class Ord3a02Base
    {		
		/// <summary>
        /// 增加一条数据
        /// </summary>
        public virtual  SqlApp Add(Model.Ord3a02 ord3a02)
        {
			StringBuilder strSql = new StringBuilder();
			strSql.Append("insert into Ord3a02(");
			strSql.Append("taxcode ,taxname ,taxpct ,agio ,plistid )");
			strSql.Append(" values (");
			strSql.Append("@taxcode ,@taxname ,@taxpct ,@agio ,@plistid )");		

			SqlParameter[] parameters = {
				new SqlParameter("@taxcode",SqlDbType.Int),
				new SqlParameter("@taxname",SqlDbType.NVarChar),
				new SqlParameter("@taxpct",SqlDbType.Decimal),
				new SqlParameter("@agio",SqlDbType.Decimal),
				new SqlParameter("@plistid",SqlDbType.NVarChar)
				};
			parameters[0].Value = ord3a02.Taxcode;
			parameters[1].Value = ord3a02.Taxname;
			parameters[2].Value = ord3a02.Taxpct;
			parameters[3].Value = ord3a02.Agio;
			parameters[4].Value = ord3a02.Plistid;
			
			return new SqlApp(strSql.ToString(),new ArrayList(parameters), false, "数据保存失败！");
        }
	
        /// <summary>
        /// 判断某个值是否存在表中的某个字段
        /// </summary>
        /// <param name="Condition">条件字段名 例:A=@A</param>
        /// <param name="hs">参数和值 如hs["@A"]=123</param>
        /// <returns></returns>
        public virtual bool Exists(String condition, Hashtable hs)
        {
			StringBuilder strSql = new StringBuilder();
			strSql.Append("select count(1) from Ord3a02 ");
			if (!string.IsNullOrEmpty(condition))
				strSql.Append(" where " + condition);
			List<SqlParameter> list = DBHelper.GetListByHashtable(hs);
			if (list.Count > 0)
				return Convert.ToInt32(DBHelper.ExecuteScalar(strSql.ToString(), list.ToArray())) > 0;
			else
				return Convert.ToInt32(DBHelper.ExecuteScalar(strSql.ToString())) > 0;
        }

		
		
		 /// <summary>
        /// 得到Sql语句
        /// </summary>
        /// <param name="Condition">Sql语句的条件</param>
		/// <param name="OrderBy">排序条件，默认为String.Empty</param>
        /// <returns></returns>
        protected virtual String GetSql(string condition,string orderBy)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select [taxcode] ,[taxname] ,[taxpct] ,[agio] ,[plistid] ");
            strSql.Append(" FROM Ord3a02 ");
 			
			if (!string.IsNullOrEmpty(condition)) strSql.Append(" where " + condition);				
			if(!string.IsNullOrEmpty(orderBy)) strSql.Append( " order by " + orderBy );
			
            return  strSql.ToString();
        }

        /// <summary>
        /// 根据条件和参数得到Ord3a02对象
        /// </summary>
        /// <param name="Condition">Sql条件</param>
        /// <param name="hs">参数和值</param>
        /// <returns></returns>
        public virtual Model.Ord3a02 GetModel(String Condition, Hashtable hs)
        {
			String sql = GetSql(Condition,String.Empty);
			DataTable dt = DBHelper.GetTableByCondition(sql,  hs);
			return (dt.Rows.Count > 0) ? Model.Ord3a02.GetOrd3a02ListByDataTable(dt)[0] : null;
        }

		
		public virtual DataTable GetList(string c,Hashtable hs)
		{
			string sql = GetSql(c,null); //得到SQL语句
			//返回结果集
			return DBHelper.GetData(sql,DBHelper.GetListByHashtable(hs).ToArray());
		}
    }
}
